* Bootstrap procedure over entire causal link:
capture program drop layersbootstrap
program define layersbootstrap, rclass

	preserve
	bsample , cluster(firmcode) idcluster(newfirmcode)
	
	sort newfirmcode t
	xtset newfirmcode t
	
	* First stage identical for all cases:
	xtreg logsales I_WID I_transport_f2 yeardummy* if sample == 1, fe
	cap drop logsalespred
	predict logsalespred, xbu

	* Second stage for organization differs for each model:

	* GMM, ma(1) errors, one-step
	xtabond2 layers L.layers logsales yeardummy* sectordummy* if sample == 1, ///
	gmmstyle(L.layers, lag(3 .) ) gmmstyle(logsales, lag(5 .) )
	cap drop layers_gmm2_all
	predict layers_gmm2_all
	
	areg log2inequality1 layers_gmm2_all logsalespred yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar log2inequality1_gmm2 = _b[layers_gmm2_all]
	return scalar log2inequality1_gmm2s = _b[logsalespred]	
	areg log2inequality2 layers_gmm2_all logsalespred yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar log2inequality2_gmm2 = _b[layers_gmm2_all]
	return scalar log2inequality2_gmm2s = _b[logsalespred]	
	areg log2inequality4 layers_gmm2_all logsalespred yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar log2inequality4_gmm2 = _b[layers_gmm2_all]
	return scalar log2inequality4_gmm2s = _b[logsalespred]
	areg log2inequality5 layers_gmm2_all logsalespred yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar log2inequality5_gmm2 = _b[layers_gmm2_all]
	return scalar log2inequality5_gmm2s = _b[logsalespred]
	areg wagegap1_topbottom_log layers_gmm2_all logsalespred yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar wagegap1_topbottom_log_gmm2 = _b[layers_gmm2_all]
	return scalar wagegap1_topbottom_log_gmm2s = _b[logsalespred]
	
	areg res2inequality1_model2 layers_gmm2_all logsalespred yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality1_gmm2 = _b[layers_gmm2_all]
	return scalar res2inequality1_gmm2s = _b[logsalespred]
	areg res2inequality2_model2 layers_gmm2_all logsalespred yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality2_gmm2s = _b[logsalespred]
	return scalar res2inequality2_gmm2 = _b[layers_gmm2_all]
	areg res2inequality4_model2 layers_gmm2_all logsalespred yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality4_gmm2s = _b[logsalespred]
	return scalar res2inequality4_gmm2 = _b[layers_gmm2_all]
	areg res2inequality5_model2 layers_gmm2_all logsalespred yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality5_gmm2 = _b[layers_gmm2_all]
	return scalar res2inequality5_gmm2s = _b[logsalespred]
	areg wagegap1_topbottom_res2 layers_gmm2_all logsalespred yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar wagegap1_topbottom_res2_gmm2s = _b[logsalespred]
	return scalar wagegap1_topbottom_res2_gmm2 = _b[layers_gmm2_all]

	
	areg res2inequality1_model4 layers_gmm2_all logsalespred yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality1_gmm2_v2 = _b[layers_gmm2_all]
	return scalar res2inequality1_gmm2s_v2 = _b[logsalespred]
	areg res2inequality2_model4 layers_gmm2_all logsalespred yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality2_gmm2_v2 = _b[layers_gmm2_all]
	return scalar res2inequality2_gmm2s_v2 = _b[logsalespred]
	areg res2inequality4_model4 layers_gmm2_all logsalespred yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality4_gmm2_v2 = _b[layers_gmm2_all]
	return scalar res2inequality4_gmm2s_v2 = _b[logsalespred]
	areg res2inequality5_model4 layers_gmm2_all logsalespred yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality5_gmm2_v2 = _b[layers_gmm2_all]
	return scalar res2inequality5_gmm2s_v2 = _b[logsalespred]
	areg wagegap1_topbottom_res4 layers_gmm2_all logsalespred yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar wagegap1_topbottom_res4_gmm2_v2 = _b[layers_gmm2_all]
	return scalar wagegap1_topbottom_res4_gmm2s_v2 = _b[logsalespred]
	
	restore
end
